#!/bin/bash

SQOOP_HOME=/usr/bin/sqoop

#上个月1日
if [[ $1 == "" ]];then
    Last_Month_DATE=$(date -d "$(date +%Y%m)01 last month" +%Y-%m-01)
else
    Last_Month_DATE=$1
fi

V_PARYEAR=`date --date="$Last_Month_DATE" +%Y`

mysql -uroot -p123456 scrm_bi -e "
delete from customer_signup_app where payment_time_year = '${V_PARYEAR}
"

${SQOOP_HOME} export \
--connect "jdbc:mysql://192.168.10.150:3306/scrm_bi?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password 123456 \
--table customer_signup_app \
--hcatalog-database itcast_dws \
--hcatalog-table customer_signup_dws \
--hcatalog-partition-keys payment_time_year  \
--hcatalog-partition-values ${V_PARYEAR} \
-m 4